package com.aidong.service;

/**
 * Created by john on 16-11-2.
 */
import com.aidong.cache.ItemCache;
import com.aidong.dao.wills.BoxRentDao;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.ContractSignConfirmDao;
import com.aidong.dao.wills.ContractSignDao;
import com.aidong.dao.wills.DicShopCodeDao;
import com.aidong.dao.wills.KyContractDao;
import com.aidong.dao.wills.MemberChangeCardDao;
import com.aidong.dao.wills.MemberChangeShopDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.dao.wills.MemberEarnestDao;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.dao.wills.MemberStopedCardDao;
import com.aidong.dao.wills.MemberTransferDao;
import com.aidong.dao.wills.PrintTemplateDao;
import com.aidong.dao.wills.PtBespeakDao;
import com.aidong.dao.wills.PtContractDao;
import com.aidong.dao.wills.PtItemCodeDao;
import com.aidong.model.LoginUser;
import com.aidong.model.wills.BoxRent;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.ContractSign;
import com.aidong.model.wills.ContractSignConfirm;
import com.aidong.model.wills.DicShopCode;
import com.aidong.model.wills.KyContract;
import com.aidong.model.wills.MemberChangeCard;
import com.aidong.model.wills.MemberChangeShop;
import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.MemberStopedCard;
import com.aidong.model.wills.MemberTransfer;
import com.aidong.model.wills.PtBespeak;
import com.aidong.model.wills.PtContract;
import com.aidong.model.wills.PtItemCode;
import com.aidong.util.FuncUtil;
import com.aidong.web.controller.svc.ContractSignController;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class PrintDataService {
    @Resource
    protected ItemCache cache;
    @Resource
    protected SysUserSession userSession;
    @Resource
    MemberContractDao memberContractDao;
    @Resource
    PtContractDao ptContractDao;
    @Resource
    MemberInfoDao memberInfoDao;
    @Resource
    MemberEarnestDao memberEarnestDao;
    @Resource
    MemberStopedCardDao memberStopedCardDao;
    @Resource
    MemberTransferDao memberTransferDao;
    @Resource
    MemberChangeShopDao memberChangeShopDao;
    @Resource
    MemberChangeCardDao memberChangeCardDao;
    @Resource
    BoxRentDao boxRentDao;
    @Resource
    ContractSignDao contractSignDao;
    @Resource
    ContractSignConfirmDao contractSignConfirmDao;
    @Resource
    DicShopCodeDao dicShopCodeDao;
    @Resource
    CardTypeCodeDao cardTypeCodeDao;
    @Resource
    PrintTemplateDao printTemplateDao;
    @Resource
    KyContractDao kyContractDao;
    @Resource
    PtBespeakDao ptBespeakDao;
    @Resource
    PtItemCodeDao ptItemCodeDao;

    public PrintDataService() {
    }

    public HashMap<String, Object> getContractPrintData(int saleId, String contractType, StringBuilder msg) {
        String data = null;
        String title = null;
        String ptjs = null;
        StringBuilder jsf = new StringBuilder();
        if("01".equals(contractType)) {
            data = this.getMemberContractData(saleId, msg, jsf);
            title = "会籍合同";
            ptjs = jsf.length() > 0?jsf.toString():"contract";
        } else if("02".equals(contractType)) {
            data = this.getPtContractData(saleId, msg, jsf);
            title = "私人训练合同";
            ptjs = jsf.length() > 0?jsf.toString():"ptcontract";
        } else if("03".equals(contractType)) {
            data = this.getMemberEarnestData(saleId, msg, jsf);
            title = "会员定金合同";
            ptjs = jsf.length() > 0?jsf.toString():"earnest";
        } else if("04".equals(contractType)) {
            data = this.getMemberStopedCardData(saleId, msg);
            title = "会员停卡合同";
            ptjs = "stopedcard";
        } else if("05".equals(contractType)) {
            data = this.getMemberTransferData(saleId, msg);
            title = "会员转让合同";
            ptjs = "transfer";
        } else if("06".equals(contractType)) {
            data = this.getMemberChangeShopData(saleId, msg);
            title = "会员转店合同";
            ptjs = "changeshop";
        } else if("07".equals(contractType)) {
            data = this.getMemberChangeCardData(saleId, msg);
            title = "会员补卡合同";
            ptjs = "changecard";
        } else if("08".equals(contractType)) {
            data = this.getBoxRentData(saleId, msg);
            title = "会员租箱合同";
            ptjs = "boxrent";
        } else if("09".equals(contractType)) {
            data = this.getKyContractData(saleId, msg);
            title = "K-Yoga合同";
            ptjs = "kycontract";
        } else if("10".equals(contractType)) {
            data = this.getPtBespeakData(saleId, msg);
            title = "私教预约";
            ptjs = "ptbespeaks";
        } else if(msg != null) {
            msg.append("合同类型错误");
        }

        if(data == null) {
            return null;
        } else {
            HashMap map = new HashMap();
            map.put("data", data);
            map.put("title", title);
            map.put("ptjs", ptjs);
            return map;
        }
    }

    public String getMemberContractData(int saleId, StringBuilder msg, StringBuilder jsfile) {
        MemberContract contract = (MemberContract)this.memberContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            Date beginTime = contract.getBeginTime();
            Date endTime = contract.getEndTime();
            if(beginTime != null && endTime != null && contract.getStatus().intValue() == 1) {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.retMsg(msg, "会员信息错误");
                } else {
                    DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(contract.getShopCode());
                    if(shop == null) {
                        return this.retMsg(msg, "门店信息错误");
                    } else {
                        CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(contract.getCardType());
                        if(cardType == null) {
                            return this.retMsg(msg, "卡种信息错误");
                        } else {
                            double amortizeFee = 0.0D;
                            if(cardType.getAmortizeFee1() != null) {
                                amortizeFee += cardType.getAmortizeFee1().doubleValue();
                            }

                            if(cardType.getAmortizeFee2() != null) {
                                amortizeFee += cardType.getAmortizeFee2().doubleValue();
                            }

                            if(cardType.getAmortizeFee3() != null) {
                                amortizeFee += cardType.getAmortizeFee3().doubleValue();
                            }

                            if(cardType.getAmortizeFee4() != null) {
                                amortizeFee += cardType.getAmortizeFee4().doubleValue();
                            }

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            DecimalFormat nf = new DecimalFormat("0.##");
                            StringBuilder sb = new StringBuilder();
                            sb.append("{saleId:").append(contract.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(contract.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(beginTime)).append("\"").append(",endTime:\"").append(sdf.format(endTime)).append("\"").append(",newEndTime:\"").append(contract.getNewEndTime() == null?"":sdf.format(contract.getNewEndTime())).append("\"").append(",cardType:\"").append(contract.getCardType()).append("\"").append(",cardTypeName:\"").append(this.cache.getValue("cardType", contract.getCardType())).append("\"").append(",factPrice:").append(contract.getFactPrice()).append("").append(",payAmount:").append(contract.getPayAmount()).append("").append(",earnestAmount:").append(contract.getEarnestAmount()).append("").append(",stopFee:").append(contract.getStopFee()).append("").append(",changeFee:").append(contract.getChangeFee()).append("").append(",mendFee:").append(contract.getMendFee()).append("").append(",chgShopFee:").append(contract.getChgShopFee()).append("").append(",amortizeFee:\"").append(nf.format(amortizeFee)).append("\"").append(",amortizeFee1:\"").append(cardType.getAmortizeFee1() == null?"":nf.format(cardType.getAmortizeFee1())).append("\"").append(",amortizeFee2:\"").append(cardType.getAmortizeFee2() == null?"":nf.format(cardType.getAmortizeFee2())).append("\"").append(",amortizeFee3:\"").append(cardType.getAmortizeFee3() == null?"":nf.format(cardType.getAmortizeFee3())).append("\"").append(",amortizeFee4:\"").append(cardType.getAmortizeFee4() == null?"":nf.format(cardType.getAmortizeFee4())).append("\"").append(",giftCardAmount:\"").append(contract.getGiftCardAmount() == null?"":nf.format(contract.getGiftCardAmount())).append("\"").append(",giftNote:\"").append(this.nvl(contract.getGiftNote())).append("\"").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "01")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf2.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("01", contract.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                            String ptfn = this.printTemplateDao.getFileNameByDate(1, contract.getSaleDate(), contract.getShopCode());
                            if(ptfn != null && ptfn.length() > 0) {
                                jsfile.append(ptfn);
                            }

                            return sb.toString();
                        }
                    }
                }
            } else {
                return this.retMsg(msg, "无效合同");
            }
        }
    }

    public String getPtContractData(int saleId, StringBuilder msg, StringBuilder jsfile) {
        PtContract contract = (PtContract)this.ptContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            Date beginTime = contract.getBeginTime();
            Date endTime = contract.getEndTime();
            if(beginTime != null && endTime != null && contract.getStatus().intValue() == 1) {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.retMsg(msg, "会员信息错误");
                } else {
                    DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(contract.getShopCode());
                    if(shop == null) {
                        return this.retMsg(msg, "门店信息错误");
                    } else {
                        PtItemCode ptItemCode = (PtItemCode)this.ptItemCodeDao.getById(contract.getPtCode());
                        if(ptItemCode == null) {
                            return this.retMsg(msg, "课程信息错误");
                        } else {
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            StringBuilder sb = new StringBuilder();
                            sb.append("{saleId:").append(contract.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(contract.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(beginTime)).append("\"").append(",endTime:\"").append(sdf.format(endTime)).append("\"").append(",ptCode:\"").append(contract.getPtCode()).append("\"").append(",ptCodeName:\"").append(this.cache.getValue("ptItemName", contract.getPtCode())).append("\"").append(",coachCode:\"").append(contract.getCoachCode()).append("\"").append(",coachName:\"").append(this.cache.getValue("ptCoachName", contract.getCoachCode())).append("\"").append(",quantity:").append(contract.getQuantity()).append("").append(",factPrice:").append(contract.getFactPrice()).append("").append(",payAmount:").append(contract.getPayAmount()).append("").append(",earnestAmount:").append(contract.getEarnestAmount()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "02")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("02", contract.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                            String ptfn = this.printTemplateDao.getFileNameByDate(ptItemCode.getMonster() != null && ptItemCode.getMonster().intValue() == 1?22:2, contract.getSaleDate(), contract.getShopCode());
                            if(ptfn != null && ptfn.length() > 0) {
                                jsfile.append(ptfn);
                            }

                            return sb.toString();
                        }
                    }
                }
            } else {
                return this.retMsg(msg, "无效合同");
            }
        }
    }

    public String getKyContractData(int saleId, StringBuilder msg) {
        KyContract contract = (KyContract)this.kyContractDao.getById(Integer.valueOf(saleId));
        if(contract == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            Date beginTime = contract.getBeginTime();
            Date endTime = contract.getEndTime();
            if(beginTime != null && endTime != null && contract.getStatus().intValue() == 1) {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.retMsg(msg, "会员信息错误");
                } else {
                    DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(contract.getShopCode());
                    if(shop == null) {
                        return this.retMsg(msg, "门店信息错误");
                    } else {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        StringBuilder sb = new StringBuilder();
                        sb.append("{saleId:").append(contract.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(contract.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(beginTime)).append("\"").append(",endTime:\"").append(sdf.format(endTime)).append("\"").append(",comboCode:\"").append(contract.getComboCode()).append("\"").append(",comboName:\"").append(this.cache.getValue("kyComboName", contract.getComboCode())).append("\"").append(",factAmount:").append(contract.getFactAmount()).append("").append(",presentAmount:").append(contract.getPresentAmount()).append("").append(",payAmount:").append(contract.getPayAmount()).append("").append(",earnestAmount:").append(contract.getEarnestAmount()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "09")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("09", contract.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                        return sb.toString();
                    }
                }
            } else {
                return this.retMsg(msg, "无效合同");
            }
        }
    }

    public String getMemberEarnestData(int saleId, StringBuilder msg, StringBuilder jsfile) {
        MemberEarnest earnest = (MemberEarnest)this.memberEarnestDao.getById(Integer.valueOf(saleId));
        if(earnest == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(earnest.getShopCode());
            if(shop == null) {
                return this.retMsg(msg, "门店信息错误");
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                DecimalFormat nf = new DecimalFormat("0.##");
                StringBuilder sb = new StringBuilder();
                sb.append("{saleId:").append(earnest.getSaleId()).append("").append(",shopCode:\"").append(earnest.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(earnest.getSaleDate())).append("\"").append(",overDueDate:\"").append(sdf.format(earnest.getOverDueDate())).append("\"").append(",earnestType:\"").append(earnest.getEarnestType()).append("\"").append(",earnestTypeName:\"").append(this.cache.getValue("earnestType", earnest.getEarnestType())).append("\"").append(",earnestAmount:").append(earnest.getEarnestAmount()).append("").append(",payAmount:").append(earnest.getPayAmount()).append("").append(",cardType:\"").append(this.nvl(earnest.getCardType())).append("\"").append(",cardTypeName:\"").append(earnest.getCardType() == null?"":this.cache.getValue("cardType", earnest.getCardType())).append("\"").append(",cardPrice:\"").append(earnest.getCardPrice() == null?"":nf.format(earnest.getCardPrice())).append("\"").append(",cardCode:\"").append(this.nvl(earnest.getCardCode())).append("\"").append(",memberCode:\"").append(this.nvl(earnest.getMemberCode())).append("\"").append(",memberName:\"").append(earnest.getCustName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", earnest.getGender())).append("\"").append(",idType:\"").append(earnest.getIdType()).append("\"").append(",idNumber:\"").append(earnest.getIdNumber()).append("\"").append(",mobile:\"").append(earnest.getMobile()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "03")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", earnest.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", earnest.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("03", earnest.getShopCode(), saleId, "")).append("\"").append("}");
                String ptfn = this.printTemplateDao.getFileNameByDate(3, earnest.getSaleDate(), earnest.getShopCode());
                if(ptfn != null && ptfn.length() > 0) {
                    jsfile.append(ptfn);
                }

                return sb.toString();
            }
        }
    }

    public String getMemberStopedCardData(int saleId, StringBuilder msg) {
        MemberStopedCard stopedCard = (MemberStopedCard)this.memberStopedCardDao.getById(Integer.valueOf(saleId));
        if(stopedCard == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(stopedCard.getContractCode());
            if(contract == null) {
                return this.retMsg(msg, "合同号错误");
            } else {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.retMsg(msg, "会员信息错误");
                } else {
                    DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(stopedCard.getShopCode());
                    if(shop == null) {
                        return this.retMsg(msg, "门店信息错误");
                    } else {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        StringBuilder sb = new StringBuilder();
                        sb.append("{saleId:").append(stopedCard.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(stopedCard.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(contract.getBeginTime())).append("\"").append(",endTime:\"").append(sdf.format(contract.getEndTime())).append("\"").append(",cardType:\"").append(contract.getCardType()).append("\"").append(",cardTypeName:\"").append(this.cache.getValue("cardType", contract.getCardType())).append("\"").append(",factPrice:").append(contract.getFactPrice()).append("").append(",payAmount:").append(stopedCard.getPayAmount()).append("").append(",earnestAmount:").append(stopedCard.getEarnestAmount()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",beginStopTime:\"").append(sdf.format(stopedCard.getBeginStopTime())).append("\"").append(",endStopTime:\"").append(sdf.format(stopedCard.getEndStopTime())).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "04")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("04", stopedCard.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                        return sb.toString();
                    }
                }
            }
        }
    }

    public String getMemberTransferData(int saleId, StringBuilder msg) {
        MemberTransfer transfer = (MemberTransfer)this.memberTransferDao.getById(Integer.valueOf(saleId));
        if(transfer == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(transfer.getContractCode());
            if(contract == null) {
                return this.retMsg(msg, "合同号错误");
            } else {
                MemberContract newContract = this.memberContractDao.getByContractCode(transfer.getNewContractCode());
                if(newContract == null) {
                    return this.retMsg(msg, "合同号错误");
                } else {
                    MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                    if(member == null) {
                        return this.retMsg(msg, "会员信息错误");
                    } else {
                        MemberInfo newMember = this.memberInfoDao.getById(transfer.getNewMemberCode());
                        if(newMember == null) {
                            return this.retMsg(msg, "会员信息错误");
                        } else {
                            DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(transfer.getShopCode());
                            if(shop == null) {
                                return this.retMsg(msg, "门店信息错误");
                            } else {
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                StringBuilder sb = new StringBuilder();
                                sb.append("{saleId:").append(transfer.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(transfer.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(contract.getBeginTime())).append("\"").append(",endTime:\"").append(sdf.format(contract.getEndTime())).append("\"").append(",cardType:\"").append(contract.getCardType()).append("\"").append(",cardTypeName:\"").append(this.cache.getValue("cardType", contract.getCardType())).append("\"").append(",factPrice:").append(contract.getFactPrice()).append("").append(",payAmount:").append(transfer.getPayAmount()).append("").append(",earnestAmount:").append(transfer.getEarnestAmount()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",newContractCode:\"").append(transfer.getNewContractCode()).append("\"").append(",newBeginTime:\"").append(sdf.format(newContract.getBeginTime())).append("\"").append(",newEndTime:\"").append(sdf.format(newContract.getEndTime())).append("\"").append(",newCardType:\"").append(newContract.getCardType()).append("\"").append(",newCardTypeName:\"").append(this.cache.getValue("cardType", newContract.getCardType())).append("\"").append(",newFactPrice:").append(newContract.getFactPrice()).append("").append(",newPayAmount:").append(newContract.getPayAmount()).append("").append(",newCardCode:\"").append(newMember.getCardCode()).append("\"").append(",newMemberCode:\"").append(newMember.getMemberCode()).append("\"").append(",newMemberName:\"").append(newMember.getChName()).append("\"").append(",newGender:\"").append(this.cache.getValue("gender", newMember.getGender())).append("\"").append(",newIdType:\"").append(newMember.getIdType()).append("\"").append(",newIdNumber:\"").append(newMember.getIdNumber()).append("\"").append(",newMobile:\"").append(newMember.getMobile()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "05")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("05", transfer.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                                return sb.toString();
                            }
                        }
                    }
                }
            }
        }
    }

    public String getMemberChangeShopData(int saleId, StringBuilder msg) {
        MemberChangeShop changeShop = (MemberChangeShop)this.memberChangeShopDao.getById(Integer.valueOf(saleId));
        if(changeShop == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(changeShop.getContractCode());
            if(contract == null) {
                return this.retMsg(msg, "合同号错误");
            } else {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.retMsg(msg, "会员信息错误");
                } else {
                    DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(changeShop.getShopCode());
                    if(shop == null) {
                        return this.retMsg(msg, "门店信息错误");
                    } else {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        StringBuilder sb = new StringBuilder();
                        sb.append("{saleId:").append(changeShop.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(changeShop.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(contract.getBeginTime())).append("\"").append(",endTime:\"").append(sdf.format(contract.getEndTime())).append("\"").append(",cardType:\"").append(contract.getCardType()).append("\"").append(",cardTypeName:\"").append(this.cache.getValue("cardType", contract.getCardType())).append("\"").append(",factPrice:").append(contract.getFactPrice()).append("").append(",payAmount:").append(changeShop.getPayAmount()).append("").append(",earnestAmount:").append(changeShop.getEarnestAmount()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",newShopCode:\"").append(changeShop.getNewShopCode()).append("\"").append(",newShopName:\"").append(this.cache.getValue("shopName", changeShop.getNewShopCode())).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "06")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("06", changeShop.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                        return sb.toString();
                    }
                }
            }
        }
    }

    public String getMemberChangeCardData(int saleId, StringBuilder msg) {
        MemberChangeCard changeCard = (MemberChangeCard)this.memberChangeCardDao.getById(Integer.valueOf(saleId));
        if(changeCard == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            MemberContract contract = this.memberContractDao.getByContractCode(changeCard.getContractCode());
            if(contract == null) {
                return this.retMsg(msg, "合同号错误");
            } else {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.retMsg(msg, "会员信息错误");
                } else {
                    DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(changeCard.getShopCode());
                    if(shop == null) {
                        return this.retMsg(msg, "门店信息错误");
                    } else {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        StringBuilder sb = new StringBuilder();
                        sb.append("{saleId:").append(changeCard.getSaleId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(changeCard.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(contract.getBeginTime())).append("\"").append(",endTime:\"").append(sdf.format(contract.getEndTime())).append("\"").append(",cardType:\"").append(contract.getCardType()).append("\"").append(",cardTypeName:\"").append(this.cache.getValue("cardType", contract.getCardType())).append("\"").append(",factPrice:").append(contract.getFactPrice()).append("").append(",payAmount:").append(changeCard.getPayAmount()).append("").append(",earnestAmount:").append(changeCard.getEarnestAmount()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",oldCardCode:\"").append(changeCard.getCardCode()).append("\"").append(",newCardCode:\"").append(changeCard.getNewCardCode()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "07")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("07", changeCard.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                        return sb.toString();
                    }
                }
            }
        }
    }

    public String getPtBespeakData(int saleId, StringBuilder msg) {
        PtBespeak bespeak = (PtBespeak)this.ptBespeakDao.getById(Integer.valueOf(saleId));
        if(bespeak == null) {
            return this.retMsg(msg, "没有这个预约");
        } else {
            MemberInfo member = this.memberInfoDao.getById(bespeak.getMemberCode());
            if(member == null) {
                return this.retMsg(msg, "会员信息错误");
            } else {
                PtContract contract = this.ptContractDao.getByContractCode(bespeak.getContractCode());
                if(contract == null) {
                    return this.retMsg(msg, "私教合同错误");
                } else {
                    ContractSign sign = this.contractSignDao.getBySaleId(saleId, "10");
                    if(sign != null && sign.getStatus().intValue() != 2 && sign.getStatus().intValue() != 3) {
                        sign = null;
                    }

                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
                    StringBuilder sb = new StringBuilder();
                    sb.append("{saleId:").append(bespeak.getAutoId()).append("").append(",contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(contract.getShopCode()).append("\"").append(",shopName:\"").append(this.cache.getValue("shopName", contract.getShopCode())).append("\"").append(",saleDate:\"").append(sdf.format(contract.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf2.format(contract.getBeginTime())).append("\"").append(",endTime:\"").append(sdf2.format(contract.getEndTime())).append("\"").append(",bespeakTime:\"").append(sdf.format(bespeak.getBespeakDate())).append("\"").append(",classTime:\"").append(sdf.format(bespeak.getClassTime())).append("\"").append(",ptCode:\"").append(bespeak.getPtCode()).append("\"").append(",ptCodeName:\"").append(this.cache.getValue("ptItemName", bespeak.getPtCode())).append("\"").append(",coachCode:\"").append(bespeak.getCoachCode()).append("\"").append(",coachName:\"").append(this.cache.getValue("ptCoachName", bespeak.getCoachCode())).append("\"").append(",quantity:").append(contract.getQuantity()).append("").append(",leftQuantity:").append(contract.getQuantity().intValue() - contract.getBespeakQuantity().intValue()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "10")).append("\"").append(",signTime:\"").append(sign == null?"":sdf.format(sign.getUpdateTime())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("10", contract.getShopCode(), saleId, contract.getContractCode())).append("\"").append("}");
                    return sb.toString();
                }
            }
        }
    }

    public String getBoxRentData(int saleId, StringBuilder msg) {
        BoxRent rent = (BoxRent)this.boxRentDao.getById(Integer.valueOf(saleId));
        if(rent == null) {
            return this.retMsg(msg, "合同号错误");
        } else {
            MemberInfo member = this.memberInfoDao.getById(rent.getMemberCode());
            if(member == null) {
                return this.retMsg(msg, "会员信息错误");
            } else {
                DicShopCode shop = (DicShopCode)this.dicShopCodeDao.getById(rent.getShopCode());
                if(shop == null) {
                    return this.retMsg(msg, "门店信息错误");
                } else {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    StringBuilder sb = new StringBuilder();
                    sb.append("{saleId:").append(rent.getSaleId()).append("").append(",shopCode:\"").append(rent.getShopCode()).append("\"").append(",shopName:\"").append(shop.getChName()).append("\"").append(",companyName:\"").append(this.nvl(shop.getCompanyName())).append("\"").append(",sealPic:\"").append(this.nvl(shop.getSealPic())).append("\"").append(",boxCode:\"").append(rent.getBoxCode()).append("\"").append(",saleDate:\"").append(sdf.format(rent.getSaleDate())).append("\"").append(",beginTime:\"").append(sdf.format(rent.getBeginTime())).append("\"").append(",endTime:\"").append(sdf.format(rent.getEndTime())).append("\"").append(",factAmount:").append(rent.getFactAmount()).append("").append(",depositAmount:").append(rent.getDepositAmount()).append("").append(",earnestAmount:").append(rent.getEarnestAmount()).append("").append(",payAmount:").append(rent.getPayAmount()).append("").append(",returnDate:\"").append(rent.getReturnDate() == null?"":sdf.format(rent.getReturnDate())).append("\"").append(",returnDeposit:").append(rent.getReturnDeposit() == null?0.0D:rent.getReturnDeposit().doubleValue()).append("").append(",addAmount:").append(rent.getAddAmount() == null?0.0D:rent.getAddAmount().doubleValue()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",memberSign:\"").append(this.getMemberSignUrl(saleId, "08")).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", rent.getSalesCode()))).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", rent.getSalesCode2()))).append("\"").append(",printDate:\"").append(sdf.format(new Date())).append("\"").append(",printUser:\"").append(this.getLoginUserCode()).append("\"").append(",printUserName:\"").append(this.cache.getValue("userName", this.getLoginUserCode())).append("\"").append(",printShopCode:\"").append(this.getLoginShopCode()).append("\"").append(",printShopName:\"").append(this.cache.getValue("shopName", this.getLoginShopCode())).append("\"").append(",printVerifyCode:\"").append(this.getPrintVerifyCode("08", rent.getShopCode(), saleId, "")).append("\"").append("}");
                    return sb.toString();
                }
            }
        }
    }

    protected String getMemberSignUrl(int saleId, String type) {
        ContractSignConfirm contractSign = this.contractSignConfirmDao.getBySaleId(saleId, type);
        String sign = "";
        if(contractSign != null && contractSign.getImageSign() != null) {
            sign = "/svc/contractSign/viewSignConfirm?saleId=" + contractSign.getSaleId() + "&contractType=" + contractSign.getContractType() + "&auth=" + ContractSignController.getAuthCode(new String[]{String.valueOf(contractSign.getSaleId()), contractSign.getContractType()});
        }

        return sign;
    }

    protected String getPrintVerifyCode(String type, String shopCode, int saleId, String contractCode) {
        return FuncUtil.Md5(type + shopCode + saleId) + FuncUtil.Md5(shopCode + contractCode).substring(0, 16);
    }

    protected String getLoginUserCode() {
        LoginUser user = this.userSession.getLoginUser();
        return user != null?user.getUserCode():null;
    }

    protected String getLoginShopCode() {
        LoginUser user = this.userSession.getLoginUser();
        return user != null?user.getShopCode():null;
    }

    protected String nvl(String s) {
        return s == null?"":s;
    }

    protected String nvl(Double s) {
        return s == null?"":s.toString();
    }

    private String retMsg(StringBuilder sb, String msg) {
        if(sb != null) {
            sb.append(msg);
        }

        return null;
    }
}

